package controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import pojo.Comment;
import service.AdminCommentService;

import java.util.List;

@Controller
public class AdminComment {
    @Autowired
    private AdminCommentService adminCommentService;
    @RequestMapping("/toDeC")
    public String initDeC(Model model){
        List<Comment> c = adminCommentService.sAC();
        model.addAttribute("c",c);
        return "adminDeleteCommentPage";}
    @RequestMapping("/deleteComment")
    public String deleteComment(Integer cid, Model model){
        int a= adminCommentService.dC(cid);
        if (a>0){
            List<Comment> c = adminCommentService.sAC();
            model.addAttribute("c",c);
            model.addAttribute("msg","删除成功！");
            return "adminDeleteCommentPage";
        }
            List<Comment> c = adminCommentService.sAC();
            model.addAttribute("c",c);
            model.addAttribute("msg","删除失败！");
            return "adminDeleteCommentPage";
    }
    @RequestMapping("/toSelOC")
    public String initSelOC(){return "adminSelectOneCommentPage";}
    @RequestMapping("/selectOneComment")
    public String selectOneComment(Integer cid,Model model){
        List<Comment> comment=adminCommentService.sOC(cid);
        model.addAttribute("comment",comment);
        if (comment.size()!=0){
            List<Comment> c=adminCommentService.sOC(cid);
            model.addAttribute("c",c);
            return "adminSelectOneCommentPage";
        }
        model.addAttribute("msg","找不到该帖子！");
        return "adminSelectOneCommentPage";
    }
    @RequestMapping("/selectAllComment")
    public String selectAllComment(Model model){
        List<Comment> comment=adminCommentService.sAC();
        model.addAttribute("comment",comment);
        return "adminSelectAllCommentPage";
    }
    @RequestMapping("/searchC")
    public String searchC(Model model){
        List<Comment> com=adminCommentService.sAC();
        model.addAttribute("com",com);
        return "adminSearchComment";
    }
}
